package http

import "github.com/gin-gonic/gin"

func NewRouterGroup(relativePath string, handlers ...gin.HandlerFunc) *RouterGroup {
	g := _gHttpEngine.Group(relativePath, handlers...)
	return &RouterGroup{g: g}
}

type RouterGroup struct {
	g *gin.RouterGroup
}

func (ts *RouterGroup) Use(middleware ...gin.HandlerFunc) {
	ts.g.Use(middleware...)
}

func (ts *RouterGroup) Get(relativePath string, handlers ...gin.HandlerFunc) {
	hand := make([]gin.HandlerFunc, 0, len(handlers)+2)
	if len(handlers) > 0 {
		hand = append(hand, handlers...)
	}
	hand = append(hand, initReq, onReq)
	ts.g.GET(relativePath, hand...)
}

func (ts *RouterGroup) Post(relativePath string, handlers ...gin.HandlerFunc) {
	hand := make([]gin.HandlerFunc, 0, len(handlers)+2)
	if len(handlers) > 0 {
		hand = append(hand, handlers...)
	}
	hand = append(hand, initReq, onReq)
	ts.g.POST(relativePath, hand...)
}

func (ts *RouterGroup) Del(relativePath string, handlers ...gin.HandlerFunc) {
	hand := make([]gin.HandlerFunc, 0, len(handlers)+2)
	if len(handlers) > 0 {
		hand = append(hand, handlers...)
	}
	hand = append(hand, initReq, onReq)
	ts.g.DELETE(relativePath, hand...)
}

func (ts *RouterGroup) Any(relativePath string, handlers ...gin.HandlerFunc) {
	hand := make([]gin.HandlerFunc, 0, len(handlers)+2)
	if len(handlers) > 0 {
		hand = append(hand, handlers...)
	}
	hand = append(hand, initReq, onReq)
	ts.g.Any(relativePath, hand...)
}

func (ts *RouterGroup) Match(methods []string, relativePath string, handlers ...gin.HandlerFunc) {
	hand := make([]gin.HandlerFunc, 0, len(handlers)+2)
	if len(handlers) > 0 {
		hand = append(hand, handlers...)
	}
	hand = append(hand, initReq, onReq)
	ts.g.Match(methods, relativePath, hand...)
}

func (ts *RouterGroup) Static(relativePath string, root string) {
	ts.g.Static(relativePath, root)
}
